<template>
  <div class="navMainWrap">
    <div class="topBar">
      <div class="headerBar">
        <Header :src="headPic"/>
      </div>
      <div class="navBar">
        <div class="fontDiv" v-for="icon in tabIcon" :key="icon.name">
          <span
            class="iconfont"
            :class="[icon.icon, {highSelect: highSelect==icon.name}]"
            @click="selectTab(icon)"
          ></span>
          <label v-if="icon.num && icon.num > 0">{{icon.num}}</label>
        </div>
      </div>
    </div>
    <div class="setBar">
      <span class="iconfont iconshezhi"></span>
    </div>
  </div>
</template>

<script type='text/ecmascript-6'>
import Header from '../comp/Header.vue';
export default {
  components: {
    Header
  },
  props: {
    chatMessageNum: {
      type: Number,
      default: 0
    },
    friendMessageNum: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      headPic: JSON.parse(localStorage.userInfo).base + JSON.parse(localStorage.userInfo).headImg,
      highSelect: 'chat',
      tabIcon: [{
        name: 'chat',
        icon: 'iconxiaoxi',
        num: this.chatMessageNum
      }, {
        name: 'friend',
        icon: 'icontongxunlu',
        num: this.friendMessageNum
      }]
    };
  },
  mounted() {
    this.highSelect = this.$route.name;
  },
  methods: {
    selectTab(item) {
      this.highSelect = item.name;
      this.$emit('select', item);
    }
  },
  watch: {
    "$route"() {
      this.highSelect = this.$route.name;
    },
    chatMessageNum(n, o) {
      this.tabIcon[0].num = n;
    },
    friendMessageNum(n, o) {
      this.tabIcon[1].num = n;
    }
  }
}
</script>

<style lang='scss' scoped>
.navMainWrap {
  $width: 60px;
  width: $width;
  height: 100%;
  background: #282c31;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  justify-content: space-between;
  .topBar {
    .headerBar {
      width: 100%;
      height: $width * 1.2;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
    }
    .navBar {
      width: 100%;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      .fontDiv {
        position: relative;
        margin: 20px 0;
        cursor: pointer;
        > span {
          font-size: 24px;
          color: #cfcbcb;
          &.highSelect {
            color: green;
          }
        }
        > label {
          position: absolute;
          top: -3px;
          right: -3px;
          border-radius: 360px;
          background: red;
          width: 15px;
          height: 15px;
          font-size: 12px;
          display: inline-block;
          line-height: 15px;
          color: #fff;
          text-align: center;
        }
      }
    }
  }
  .setBar {
    width: 100%;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    > span {
      font-size: 24px;
      margin: 20px 0;
      color: #cfcbcb;
    }
  }
}
</style>